home *** CD-ROM | disk | FTP | other *** search
- /**************************************************************************
- *
- * Copyright (c) 1992 Silicon Graphics, Inc.
- * All Rights Reserved
- *
- * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SGI
- *
- * The copyright notice above does not evidence any actual of intended
- * publication of such source code, and is an unpublished work by Silicon
- * Graphics, Inc. This material contains CONFIDENTIAL INFORMATION that is
- * the property of Silicon Graphics, Inc. Any use, duplication or
- * disclosure not specifically authorized by Silicon Graphics is strictly
- * prohibited.
- *
- * RESTRICTED RIGHTS LEGEND:
- *
- * Use, duplication or disclosure by the Government is subject to
- * restrictions as set forth in subdivision (c)(1)(ii) of the Rights in
- * Technical Data and Computer Software clause at DFARS 52.227-7013,
- * and/or in similar or successor clauses in the FAR, DOD or NASA FAR
- * Supplement. Unpublished - rights reserved under the Copyright Laws of
- * the United States. Contractor is SILICON GRAPHICS, INC., 2011 N.
- * Shoreline Blvd., Mountain View, CA 94039-7311
- **************************************************************************
- *
- * File: writeone.c
- *
- * Description: A libstiff example program that simply reads an X format
- * bitmap image and writes it to a STIFF format file. This program
- * demonstrates the use of the libstiff functions that write
- * STIFF files intended for printing. These are the so called Print
- * STIFF (PST) functions. These functions write a STIFF format file
- * with additional tags that may be of use to printer drivers and
- * filter programs.
- *
- * The resulting STIFF image is written to stdout and can be sent to
- * a file using redirection.
- *
- * Usage: writeone
- *
- **************************************************************************/
-
-
- #ident "$Revision: 1.6 $"
-
-
- #include <stdio.h>
- #include "printstiff.h"
-
-
- /*
- * Each byte of an X Bitmap files present the image data low order bit
- * containing the data to be printed first and the high order bit containing
- * the data to be printed last. A TIFF file needs the bits in the reverse
- * order. Therefore, we will set up a union that will allow us to easily
- * reverse the bits in each image byte.
- */
-
- typedef struct {
- unsigned char b0:1;
- unsigned char b1:1;
- unsigned char b2:1;
- unsigned char b3:1;
- unsigned char b4:1;
- unsigned char b5:1;
- unsigned char b6:1;
- unsigned char b7:1;
- } byte_t;
-
- union {
- unsigned char byte;
- byte_t bits;
- } item;
-
-
- /*
- * We will use the X bitmap that represents a 64 x 64 pixel X
- * Logo. If a different bitmap is desired simply change the
- * include and the size and data defines.
- */
-
- #include <X11/bitmaps/xlogo64>
-
- #define IMAGE_WIDTH xlogo64_width
- #define IMAGE_HEIGHT xlogo64_height
- #define IMAGE_DATA xlogo64_bits
-
-
- int main(int argc, char *argv[])
- {
- STStream *sptr;
- STImageHeader header;
- PSTImageHeader pheader;
- register int i, j;
- register unsigned char c;
- int amount;
-
- /*
- * Compute amount of data to be written
- */
- amount = ((IMAGE_WIDTH + 7)/8 * 8 * IMAGE_HEIGHT) / 8;
-
- /*
- * As indicated above a bit reversal must be performed
- * on the bitmap image data. Perform that reversal
- */
- for (i = 0; i < amount; i++) {
- item.byte = IMAGE_DATA[i];
-
- j = item.bits.b0;
- item.bits.b0 = item.bits.b7;
- item.bits.b7 = j;
-
- j = item.bits.b1;
- item.bits.b1 = item.bits.b6;
- item.bits.b6 = j;
-
- j = item.bits.b2;
- item.bits.b2 = item.bits.b5;
- item.bits.b5 = j;
-
- j = item.bits.b3;
- item.bits.b3 = item.bits.b4;
- item.bits.b4 = j;
-
- IMAGE_DATA[i] = item.byte;
- }
-
- /*
- * File in the Print STIFF Image header structure
- */
- /* Base STIFF information */
- pheader.width = IMAGE_WIDTH;
- pheader.height = IMAGE_HEIGHT;
- pheader.bitsPerSample = 1;
- pheader.samplesPerPixel = 1;
- pheader.imgbytes = amount;
- pheader.type = ST_TYPE_K;
- pheader.plane = ST_PLANE_PACKED;
- /* Print STIFF additional information */
- pheader.resUnit = PST_RES_UNIT_INCH;
- pheader.xRes = 300;
- pheader.yRes = 300;
- pheader.thresholding = PST_THRESHOLD_NONE;
- pheader.compression = PST_COMPRESSION_NONE;
- pheader.dateTime = "1992:10:02 23:10:12";
- pheader.hostComputer = "SGI Iris";
- pheader.software = argv[0];
- pheader.docName = "X Bitmap";
- pheader.pageNumbers[0] = 1;
- pheader.pageNumbers[1] = 1;
- pheader.targetPrinter = "Color Raster: HP DeskJet 500C";
- pheader.driverOptions = "-n 1 -m 300";
-
- /*
- * Display the header information that will be written
- * to the file
- */
- fprintf(stderr, "PST Image Header\n");
- /* Base STIFF information */
- fprintf(stderr, "\tImage width: %ld\n", pheader.width);
- fprintf(stderr, "\tImage height: %ld\n", pheader.height);
- fprintf(stderr, "\tBits per sample: %d\n", pheader.bitsPerSample);
- fprintf(stderr, "\tSamples per pixel: %d\n", pheader.samplesPerPixel);
- fprintf(stderr, "\tImage size (bytes): %ld\n", pheader.imgbytes);
- fprintf(stderr, "\tImage type: %d\n", pheader.type);
- fprintf(stderr, "\tData format: %d\n", pheader.plane);
- /* Print STIFF additional information */
- fprintf(stderr, "\tResolution unit: %d\n", pheader.resUnit);
- fprintf(stderr, "\tX Resolution: %d\n", pheader.xRes);
- fprintf(stderr, "\tY Resolution: %d\n", pheader.yRes);
- fprintf(stderr, "\tThresholding: %d\n", pheader.thresholding);
- fprintf(stderr, "\tCompression: %d\n", pheader.compression);
- fprintf(stderr, "\tDate/time: %s\n", pheader.dateTime);
- fprintf(stderr, "\tHost computer: %s\n", pheader.hostComputer);
- fprintf(stderr, "\tSoftware: %s\n", pheader.software);
- fprintf(stderr, "\tDocument name: %s\n", pheader.docName);
- fprintf(stderr, "\tCurrent page number: %d\n", pheader.pageNumbers[0]);
- fprintf(stderr, "\tTotal pages: %d\n", pheader.pageNumbers[1]);
- fprintf(stderr, "\tTarget printer: %s\n", pheader.targetPrinter);
- fprintf(stderr, "\tDriver options: %s\n", pheader.driverOptions);
-
- /*
- * Open a STIFF stream for the stdout
- */
- if ((sptr = STOpen(fileno(stdout), ST_WRITE)) == NULL) {
- STPerror(argv[0]);
- exit(1);
- }
-
- /*
- * Write a Print STIFF image header
- */
- if (PSTWriteImageHeader(sptr, &pheader, 0) < 0) {
- STPerror(argv[0]);
- exit(1);
- }
-
- /*
- * Wirte the image data
- */
- if (STWrite(sptr, IMAGE_DATA, pheader.imgbytes) < 0) {
- STPerror(argv[0]);
- exit(1);
- }
-
- /*
- * Close the STIFF stream
- */
- if (STClose(sptr) < 0) {
- STPerror(argv[0]);
- exit(1);
- }
-
- return 0;
- }
-